#!/usr/bin/env node

const { config, getAccessToken } = require('./index.js')
const https = require('https')

function clearRepo( name, owner = "", is_org = false ) {
    console.log( "clearRepo: " + name + " of " + owner )
    var url = "https://gitee.com/api/v5/repos" + "/" + owner + "/" + name + "/clear" + "?access_token=" + getAccessToken() + "&name=" + name
    console.log( "url: " + url )

    https.request( url, {
        method: "PUT"
    }, ( res ) => {
        console.log( "" + res.statusCode )
    } ).on( "error", ( error ) => {
    } ).end()
}

if (config.type == 'user') {
    clearRepo(config.name)
} else if (config.type == 'orgs') {
    clearRepo(config.owner, config.name, true)
}